package com.example.administrator.hqq.activity.group;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.base.MyActivity;
import com.example.administrator.hqq.config.LoongsConfig;
import com.example.horizontalselectedviewlibrary.HorizontalselectedView;
import com.zhy.autolayout.AutoRelativeLayout;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置群限制
 */
public class SelectNumbeActivity extends MyActivity {
    @BindView(R.id.return_auto)
    AutoRelativeLayout returnAuto;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.hd_main)
    HorizontalselectedView hdMain;
    @BindView(R.id.bracket)
    TextView bracket;
    @BindView(R.id.locality)
    RadioButton locality;
    @BindView(R.id.locality_unlimited)
    RadioButton localityUnlimited;
    @BindView(R.id.location_prefer)
    RadioGroup locationPrefer;
    @BindView(R.id.man)
    RadioButton man;
    @BindView(R.id.woman)
    RadioButton woman;
    @BindView(R.id.man_unlimited)
    RadioButton manUnlimited;
    @BindView(R.id.gender_prefer)
    RadioGroup genderPrefer;
    @BindView(R.id.age)
    RadioButton age;
    @BindView(R.id.age_unlimited)
    RadioButton ageUnlimited;
    @BindView(R.id.age_prefer)
    RadioGroup agePrefer;
    @BindView(R.id.skip_activity)
    TextView skipActivity;
    @BindView(R.id.skip_activity_auto)
    RelativeLayout skipActivityAuto;
    private List<String> strings;
    private String max_member = "";
    private String gender_prefer = "";
    private String location_prefer = "";
    private String age_prefer = "";
    private RadioButton radioButton = null;
    private String TAG = this.getClass().getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_numbe);
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {
        bracket.setText("<");
        strings = new ArrayList<>();
        for (int i = 2; i < 11; i++) {
            strings.add(i + "");
        }
        hdMain.setData(strings);
    }

    @SuppressLint("ResourceAsColor")
    public void setPitchUpTextColor(RadioButton rad) {
        switch (rad.getId()){
            case R.id.locality:
            case R.id.locality_unlimited:
                locality.setTextColor(Color.parseColor("#000000"));
                localityUnlimited.setTextColor(Color.parseColor("#000000"));
                break;
            case R.id.man:
            case R.id.woman:
            case R.id.man_unlimited:
                man.setTextColor(Color.parseColor("#000000"));
                woman.setTextColor(Color.parseColor("#000000"));
                manUnlimited.setTextColor(Color.parseColor("#000000"));
                break;
            case R.id.age:
            case R.id.age_unlimited:
                age.setTextColor(Color.parseColor("#000000"));
                ageUnlimited.setTextColor(Color.parseColor("#000000"));
                break;
        }
        rad.setTextColor(Color.parseColor("#00ae9d"));
    }

    @OnClick({R.id.return_auto,R.id.locality, R.id.locality_unlimited, R.id.man, R.id.woman, R.id.man_unlimited, R.id.age, R.id.age_unlimited, R.id.skip_activity_auto})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.return_auto:
                finish();
                break;
            case R.id.locality:
                location_prefer = "1";
                setPitchUpTextColor(locality);
                break;
            case R.id.locality_unlimited:
                setPitchUpTextColor(localityUnlimited);
                location_prefer = "0";
                break;
            case R.id.man:
                gender_prefer = "1";
                setPitchUpTextColor(man);
                break;
            case R.id.woman:
                gender_prefer = "2";
                setPitchUpTextColor(woman);
                break;
            case R.id.man_unlimited:
                gender_prefer = "0";
                setPitchUpTextColor(manUnlimited);
                break;
            case R.id.age:
                age_prefer = "1";
                setPitchUpTextColor(age);
                break;
            case R.id.age_unlimited:
                age_prefer = "0";
                setPitchUpTextColor(ageUnlimited);
                break;
            case R.id.skip_activity_auto:
                max_member = hdMain.getSelectedString();
                if (TextUtils.isEmpty(location_prefer)){
                    ToastUtils.showShort("请选择地区限制");
                    return;
                }
                if (TextUtils.isEmpty(gender_prefer)){
                    ToastUtils.showShort("请选择性别限制");
                    return;
                }
                if (TextUtils.isEmpty(age_prefer)){
                    ToastUtils.showShort("请选择年龄限制");
                    return;
                }
                Log.e(TAG, "onViewClicked:" + "最大人数:  " + max_member + "  性别:" + gender_prefer + "  地区:" + location_prefer + "年龄:" + age_prefer);
                Intent intent = new Intent(this, SkipCreateGroupActivity.class);
                intent.putExtra(LoongsConfig.title, getIntent().getStringExtra(LoongsConfig.title));
                intent.putExtra(LoongsConfig.url, getIntent().getStringExtra(LoongsConfig.url));
                intent.putExtra(LoongsConfig.max_member, max_member);
                intent.putExtra(LoongsConfig.location_prefer, location_prefer);
                intent.putExtra(LoongsConfig.gender_prefer, gender_prefer);
                intent.putExtra(LoongsConfig.age_prefer, age_prefer);
                intent.putExtra(LoongsConfig.topic_id,getIntent().getStringExtra(LoongsConfig.topic_id));
                intent.putExtra(LoongsConfig.group_id,getIntent().getStringExtra(LoongsConfig.group_id));
                startActivity(intent);
                break;
        }
    }

    @Override
    protected String getActivityName() {
        return this.getClass().getSimpleName();
    }
}
